package com.hzdl.apple.dao.imp;

import com.hzdl.apple.bean.Good;
import com.hzdl.apple.dao.BaseDaoImp;
import com.hzdl.apple.dao.GoodsDao;
import com.hzdl.apple.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;



public class GoodsDaoImp extends BaseDaoImp implements GoodsDao {
	private String sql;
	private QueryRunner qr;
	
	public GoodsDaoImp() {
		qr=new QueryRunner(DruidUtils.dataSource);
	}

	@Override
	public boolean addGoods(Good good, Connection Conn) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Good getGoodById(int GID, Connection Conn) {
		sql="select * from goods where GoodsID=?";
		try {
			return qr.query(Conn, sql,new BeanHandler<>(Good.class),GID);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<Good> getGoods(String GoodsName) {
		sql="select * from goods where GoodsName=?";
		try {
			return qr.query(sql, new BeanListHandler<>(Good.class), GoodsName);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Good getGoodByName(String GoodsName,Connection Conn) {
		sql="select * from goods where GoodsName=?";
		Good good=null;
				
		try {
			good=qr.query(sql, new BeanHandler<>(Good.class),GoodsName);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
				return good;
	}

	

}
